package com.normal.practise.response;

import com.normal.practise.enums.ResultEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * @Author SiYao.Lee
 * @Since 2020-09-15
 *
 * 公用返回结果类
 */
@Data
public class ResponseResult<T> implements Serializable {

    private int code;
    private String msg;
    private T data;

    public ResponseResult() {

    }

    public ResponseResult(int code, String msg) {
        super();
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult(int code, String msg, T data) {
        super();
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 处理成功 无返回内容
     */
    public static ResponseResult successResult() {
        return new ResponseResult(ResultEnum.RESULT_SUCCESS.getCode(),
                ResultEnum.RESULT_SUCCESS.getMsg());
    }

    /**
     * 处理成功 返回信息
     */
    public static ResponseResult successResult(String msg) {
        return new ResponseResult(ResultEnum.RESULT_SUCCESS.getCode(), msg);
    }

    /**
     * 处理成功 返回信息和字符串结果
     */
    public static ResponseResult successResult(String msg, String resultString) {
        return new ResponseResult(ResultEnum.RESULT_SUCCESS.getCode(), msg, resultString);
    }

    /**
     * 处理成功 返回信息和结果
     **/
    public static ResponseResult successResult(String msg, Object data) {
        return new ResponseResult(ResultEnum.RESULT_SUCCESS.getCode(), msg, data);
    }

    /**
     * 处理成功 返回对象
     */
    public static ResponseResult successResult(Object obj) {
        return new ResponseResult(ResultEnum.RESULT_SUCCESS.getCode(),
                ResultEnum.RESULT_SUCCESS.getMsg(),
                obj);
    }

    /**
     * 处理失败返回
     */
    public static ResponseResult errorResult(Object obj) {
        return new ResponseResult(ResultEnum.RESULT_ERROR.getCode(),
                ResultEnum.RESULT_ERROR.getMsg(),
                obj);
    }

    /**
     * 处理失败加提示错误
     **/
    public static ResponseResult errorResult(String errmsg) {
        return new ResponseResult(ResultEnum.RESULT_ERROR.getCode(),
                errmsg);
    }

    /**
     * 处理失败返回  无返回内容
     */
    public static ResponseResult errorResult() {
        return new ResponseResult(ResultEnum.RESULT_ERROR.getCode(),
                ResultEnum.RESULT_ERROR.getMsg()
        );
    }

    /**
     * 处理错误 参数:枚举
     **/
    public static ResponseResult errorResult(ResultEnum resultEnum) {
        return new ResponseResult(resultEnum.getCode(), resultEnum.getMsg());
    }

    /**
     * 处理错误 返回自定义信息
     **/
    public static ResponseResult errorResult(int code, String msg) {
        return new ResponseResult(code, msg);
    }

    /**
     * 处理错误 返回自定义信息
     */
    public static ResponseResult errorResult(ResultEnum resultEnum, Object obj) {
        return new ResponseResult(resultEnum.getCode(), resultEnum.getMsg(), obj);
    }
}